<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8"/>
  <title>首页</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  <th:block th:include="common/pub_head :: default"></th:block>
  <th:block th:include="common/pub_head :: layui"></th:block>
  <link rel="stylesheet" th:href="@{/fly/css/global.css}"/>
  <style>
    .layui-fixbar {
      display: none;
    }

    .my {
      color: #009688 !important;
    }

    .layui-form-switch {
      margin-top: 0;
      margin-right: 10px;
    }
  </style>
</head>
<body>
<div class="fly-header layui-bg-black">
  <div>
    <a class="fly-logo" href="javaScript:void(0)">
      <img th:src="@{/fly/images/logo.png}" alt="layui"/>
    </a>
    <ul class="layui-nav fly-nav layui-hide-xs">
      <li class="layui-nav-item specialColumn">
        <a th:href="@{/dic/library}" target="iframeChild" class="my">
          <i class="iconfont icon-jiaoliu"></i>题库</a>
      </li>
      <li class="layui-nav-item specialColumn">
        <a th:href="@{/answer/list}" target="iframeChild"><i class="layui-icon layui-icon-set"></i>题库管理</a>
      </li>
      <li class="layui-nav-item specialColumn">
        <a th:href="@{/answer/log/list}" target="iframeChild"><i class="layui-icon layui-icon-log"></i>答题记录</a>
      </li>
      <li class="layui-nav-item specialColumn">
        <a th:href="@{/answer/uploadAnswer}" target="iframeChild"><i class="layui-icon layui-icon-file-b"></i>单题库上传</a>
      </li>
      <!--      <li class="layui-nav-item specialColumn">-->
      <!--        <a th:href="@{/answer/uploadAnswer}" target="iframeChild"><i class="layui-icon layui-icon-component"></i>答题情况分析-->
      <!--        </a>-->
      <!--      </li>-->
      <li class="layui-nav-item specialColumn">
        <a th:href="@{/answer/error/list}" target="iframeChild"><i class="layui-icon layui-icon-set"></i>错题集管理
        </a>
      </li>
      <!--<li class="layui-nav-item">
        <a href="case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
      </li>
      <li class="layui-nav-item">
        <a href="http://www.layui.com/" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
      </li>-->
    </ul>

    <ul class="layui-nav" style="position:absolute;top:0;right: 110px;">
      <li class="layui-nav-item">
        <a class="fly-nav-avatar" href="javascript:void(0);">
          欢迎：
          <cite class="layui-hide-xs" th:text="${userName}"></cite>
          <img src="https://tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg">
        </a>
        <dl class="layui-nav-child">
          <dd><a th:href="@{/loginOut}" style="text-align: center;">退出登录</a></dd>
        </dl>
      </li>
      <!--      <li class="layui-nav-item">-->
      <!--        <a class="fly-nav-avatar" href="javascript:refreshInit()">-->
      <!--          重置系统-->
      <!--        </a>-->
      <!--      </li>-->
    </ul>
    <ul class="layui-nav" style="position:absolute;top:0;right: 0;">
      <li class="layui-nav-item">
        <form class="layui-form" id="signInform">
          <span style="color: rgba(255, 255, 255, .7)">签到：</span>
          <input type="checkbox" id="signIn" name=switch" lay-skin="switch" lay-filter="signIn">
        </form>
      </li>
    </ul>
  </div>
</div>
<iframe th:src="@{/dic/library}" scrolling="auto" frameborder="no" border="0" name="iframeChild" id="iframeChild"
        width="100%"></iframe>
<script>
  window.addEventListener('message', function (e) {
    var fun = e.data;
    if (fun == "signIn") {
      signIn(true);
    }
  });

  function signIn(flag) {
    if (flag) {
      var style = document.createElement('style');
      style.type = 'text/css';
      style.innerHTML = ".layui-form-switch{background-color:#5FB878;border-color:#5FB878} " +
          ".layui-form-switch i{left:26px} " +
          ".layui-disabled, .layui-disabled:hover{cursor:pointer !important} " +
          ".layui-checkbox-disbaled, .layui-checkbox-disbaled i{border-color:transparent !important}";
      document.getElementsByTagName('HEAD').item(0).appendChild(style);
      $('#signIn').attr('disabled', 'disabled');
    }
  }
</script>
<script th:inline="javascript">
  /*<![CDATA[*/
  var flag = [[${isSignIn}]];
  signIn(flag);

  function refreshInit() {
    layer.confirm("确定要重置系统吗？", function () {
      window.location.href = path + "/refresh/init";
    });
  }

  $(document).on("click", ".specialColumn", function () {
    $(".specialColumn").find("a").removeClass("my");
    $(this).find("a").addClass("my");
  });

  function uploadAnswer() {
    var URL = path + "/answer/uploadAnswer";
    $("#iframeChild").attr("src", URL);
  }

  $("#iframeChild").height($(document).height() - 70);
  $(window).resize(function () {
    $("#iframeChild").height($(document).height() - 70);
  });

  var URL = path + "/user/me";
  var formData = {};
  $.post(URL, formData, function (userBean) {
    var domEle = "";
    if (userBean.id != -1) {
      domEle += "<li class='layui-nav-item'>\n" +
          "        <a class='fly-nav-avatar' href='javascript:void(0);'>\n" +
          "          <cite class='layui-hide-xs'>" + userBean.displayName + "</cite>\n" +
          "          <img src='" + userBean.avatar + "'>\n" +
          "        </a>\n" +
          "      </li>";
      domEle += "<li class='layui-nav-item'>\n" +
          "        <a href='/signOut'>退出</a>\n" +
          "      </li>";
      $(".fly-nav-user").html(domEle);
    }
  }, "json");
  /*]]>*/
</script>
<script>
  layui.use(['form','element'], function () {
    var form = layui.form;
    //实例化element
    var element = layui.element;
    form.on('switch(signIn)', function (data) {
      $.ajax({
        url: path + '/signIn',
        type: 'post',
        success: function () {
          $('#signIn').attr('disabled', 'disabled');
          layer.msg('签到成功', {icon: 6});
        }
      });
    });
  });
</script>
</body>
</html>